home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 26 / Cream of the Crop 26.iso / program / ddj0897.zip / DYN401.ZIP / class / memory.c < prev    next >
C/C++ Source or Header  |  1997-04-16  |  3KB  |  122 lines

  1.  
  2.  
  3. /*  Copyright (c) 1993-1996 Algorithms Corporation  */
  4. /*  All rights reserved.  */
  5.  
  6.  
  7.  
  8.  
  9. /*  This file automatically generated by dpp - do not edit  */
  10.  
  11. #define    DPP_STRATEGY    2
  12. #define    DPP_FASTWIDE    0
  13.  
  14.  
  15.  
  16.  
  17. #define    CLASS    Memory_c
  18. #define    ivType    Memory_iv_t
  19.  
  20. #include "generics.h"
  21.  
  22. object    Memory_c;
  23.  
  24.  
  25. #line 26 "memory.c"
  26. typedef struct  _Memory_iv_t  {
  27.     unsigned iSize;
  28.     void * iPtr;
  29. }    Memory_iv_t;
  30.  
  31.  
  32. #line 21 "memory.d"
  33. #include <string.h> 
  34.  
  35. cmeth objrtn Memory_cm_gNewWithInt(object self, int size)
  36.     object obj = oSuper(Memory_c, gNew, self)(self); 
  37.     accessIVsOf(obj); 
  38.     iv->iSize = (unsigned) size; 
  39.     iv->iPtr = calloc(iv->iSize ? iv->iSize : 1, sizeof(char)); 
  40.     if (!iv->iPtr) 
  41.         gError(Dynace, "Dynace: out of memory."); 
  42.     return obj; 
  43.  
  44. imeth objrtn Memory_im_gDispose(object self)
  45. { Memory_iv_t *iv = GetIVs(Memory, self);
  46.     if (iv->iPtr) 
  47.         free(iv->iPtr); 
  48.     return oSuper(Memory_c, gDispose, self)(self); 
  49.  
  50. imeth void * Memory_im_gPointerValue(object self)
  51. { Memory_iv_t *iv = GetIVs(Memory, self);
  52.     return iv->iPtr; 
  53.  
  54. imeth int Memory_im_gSize(object self)
  55. { Memory_iv_t *iv = GetIVs(Memory, self);
  56.     return iv->iSize; 
  57.  
  58. imeth objrtn Memory_im_gResize(object self, int size)
  59. { Memory_iv_t *iv = GetIVs(Memory, self);
  60.     iv->iSize = (unsigned) size; 
  61.     iv->iPtr = realloc(iv->iPtr, iv->iSize ? iv->iSize : 1); 
  62.     if (!iv->iPtr) 
  63.         gError(Dynace, "Dynace: out of memory."); 
  64.     return self; 
  65.  
  66. imeth objrtn Memory_im_gDeepCopy(object self)
  67. { Memory_iv_t *iv = GetIVs(Memory, self);
  68.     object cpy = gNewWithInt(CLASS, (int) iv->iSize); 
  69.     ivType *iv2 = ivPtr(cpy); 
  70.     memcpy(iv2->iPtr, iv->iPtr, iv->iSize); 
  71.     return cpy; 
  72.  
  73.  
  74. #line 82 "memory.c"
  75.  
  76. objrtn    Memory_initialize(void)
  77. {
  78.     static  CRITICALSECTION  cs;
  79.     static  int volatile once = 0;
  80.  
  81.     ENTERCRITICALSECTION(_CI_CS_);
  82.     if (!once) {
  83.         INITIALIZECRITICALSECTION(cs);
  84.         once = 1;
  85.     }
  86.     LEAVECRITICALSECTION(_CI_CS_);
  87.  
  88.     ENTERCRITICALSECTION(cs);
  89.  
  90.     if (Memory_c) {
  91.         LEAVECRITICALSECTION(cs);
  92.         return Memory_c;
  93.     }
  94.     INHIBIT_THREADER;
  95.     Memory_c = gNewClass(Class, "Memory", sizeof(Memory_iv_t), 0, END);
  96.     cMethodFor(Memory, gNewWithInt, Memory_cm_gNewWithInt);
  97.     iMethodFor(Memory, gPointerValue, Memory_im_gPointerValue);
  98.     iMethodFor(Memory, gSize, Memory_im_gSize);
  99.     iMethodFor(Memory, gDispose, Memory_im_gDispose);
  100.     iMethodFor(Memory, gGCDispose, Memory_im_gDispose);
  101.     iMethodFor(Memory, gCopy, Memory_im_gDeepCopy);
  102.     iMethodFor(Memory, gDeepDispose, Memory_im_gDispose);
  103.     iMethodFor(Memory, gResize, Memory_im_gResize);
  104.     iMethodFor(Memory, gDeepCopy, Memory_im_gDeepCopy);
  105.  
  106.     ENABLE_THREADER;
  107.  
  108.     LEAVECRITICALSECTION(cs);
  109.  
  110.     return Memory_c;
  111. }
  112.  
  113.  
  114.  
  115.